package com.xxtx.trade.web.userCenter;


import com.xxtx.trade.common.util.model.Result;
import com.xxtx.trade.sysUser.dto.TradeSysRoleDto;
import com.xxtx.trade.sysUser.dto.TencentInfoDto;
import com.xxtx.trade.sysUser.service.TradeSysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@RestController
@RequestMapping("/api/v1/xxtx/tencent")
public class SysTencentController {
    @Autowired
    private TradeSysUserService tradeSysUserService;

    /**
     * 视频号链接，数据入口
     * */
    @RequestMapping(value = "/get/dianji/zj", method = RequestMethod.GET)
    public Result GetDianJiShiPinHao(HttpServletResponse response, HttpServletRequest request) throws IOException{

        System.out.println("收到回调==============================");

        Result<Object> result = new Result<>();
        TencentInfoDto dto = new TencentInfoDto();
        String myName = request.getParameter("myName");
        if (myName==null || myName.equals("")){
            result.setMessage("no urlName");
            return result;
        }
        dto.setUrlName(myName);

        String muid = request.getParameter("muid");
        if (muid == null) {
            muid = "";
        }
        dto.setMuid(muid);
        // 点击时间是时间戳，以秒为单位
        String click_time = request.getParameter("click_time");
        if (click_time == null) {
            click_time = "";
        }
        dto.setClick_time(click_time);

        String advertiser_id = request.getParameter("advertiser_id");
        if (advertiser_id == null) {
            advertiser_id = "";
        }
        dto.setAdvertiser_id(advertiser_id);

        String android_id = request.getParameter("android_id");
        if (android_id == null) {
            android_id = "";
        }
        dto.setAndroid_id(android_id);

        String user_agent = request.getParameter("user_agent");
        if (user_agent == null) {
            user_agent = "";
        }else {
            if (user_agent.length()>100){
                user_agent = user_agent.substring(0, 100);
            }
        }
        dto.setUser_agent(user_agent);

        String campaign_id = request.getParameter("campaign_id");
        if (campaign_id == null) {
            campaign_id = "";
        }
        dto.setCampaign_id(campaign_id);

        String agent_id = request.getParameter("agent_id");
        if (agent_id == null) {
            agent_id = "";
        }
        dto.setAgent_id(agent_id);

        String click_sku_id = request.getParameter("click_sku_id");
        if (click_sku_id == null) {
            click_sku_id = "";
        }
        dto.setClick_sku_id(click_sku_id);

        String site_set = request.getParameter("site_set");
        if (site_set == null) {
            site_set = "";
        }else {
            if (site_set.length()>100){
                site_set = site_set.substring(0, 100);
            }
        }
        dto.setSite_set(site_set);

        String oaid = request.getParameter("oaid");
        if (oaid == null) {
            oaid = "";
        }
        dto.setOaid(oaid);

        tradeSysUserService.insertShiPinHaoDatas(dto);
        return result;
    }

    /**
     * 按权限查看数据
     * */
    @RequestMapping(value = "/list/permissionInfo", method = RequestMethod.POST)
    public Result permissionTencentListInfo(@RequestBody TradeSysRoleDto tradeSysRoleDto){
        return tradeSysUserService.tencentPermissionInfoList(tradeSysRoleDto);
    }

    @RequestMapping(value = "/permissionList/all", method = RequestMethod.POST)
    public Result permissionListAll(@RequestBody TradeSysRoleDto tradeSysRoleDto) {
        return tradeSysUserService.selectPermissionTencentUrls(tradeSysRoleDto);
    }

}
